﻿using PowerHub.MES.DTO.Shopfloor.QueryDTO;
using PowerHub.MES.EFBase;
using PowerHub.MES.Entities.Shopfloor;
using PowerHub.MES.Entities;
using PowerHub.MES.IRepository.IShopfloor;
using PowerHub.MES.ReturnEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PowerHub.MES.Entities.Log;
using PowerHub.MES.IRepository.ILog;
using Microsoft.EntityFrameworkCore;

namespace PowerHub.MES.Repository.Log
{
    /// <summary>
    ///数据实现层
    /// </summary>
    public class Log_RequestRepository : BaseRepository<Log_Request>, ILog_RequestRepository
    {
        private PowerHubMesContext _repositorySys;
        public Log_RequestRepository(PowerHubMesContext repositorySys) : base(repositorySys)
        {
            _repositorySys = repositorySys;
        }


        /// <summary>
        /// 添加操作日志
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<OperationResult<bool>> CreateLog_RequestAsync(Log_Request query)
        {
            var result = new OperationResult<bool>();
            result.Data = false;

            if (AddEntity(query) > 0)
            {
                result.Data = true;
            }

            return result;
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<OperationResult<bool>> DeletionLog_RequestAsync(List<string>? ids)
        {
            var result = new OperationResult<bool>();

            var Departments = GetEntitys().AsNoTracking().Where(p => ids.Contains(p.Id)).ToList();
            Departments.ForEach(w => w.IsDel = 1);
            result.Data = UpdataEntityRange(Departments) > 0 ? true : false;

            return result;
        }

        /// <summary>
        /// 获取操作日志列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        //public async Task<OperationPageResult<List<Log_Request>>> GetLog_RequestPageListAsync(QueryLog_RequestDTO query)
        //{
        //    var result = new OperationPageResult<List<Log_Request>>();

        //    var currentQuery = GetEntitys().AsNoTracking()
        //                                    .Where(p => p.IsDel == 0).Where(p => p.RequestName
        //                                    .Contains(query.RequestName ?? string.Empty));

        //    result.PageIndex = query.PageIndex;
        //    result.PageSize = query.PageSize;
        //    result.TotalCount = await currentQuery.CountAsync();

        //    if (result.TotalCount > 0)
        //    {
        //        result.Data = await currentQuery.OrderByDescending(g => g.Createtime).Skip((query.PageIndex - 1) * query.PageSize).Take(query.PageSize).ToListAsync();
        //    }

        //    return result;
        //}

        /// <summary>
        /// 更新操作日志
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<OperationResult<bool>> UpdateLog_RequestAsync(Log_Request query)
        {
            var result = new OperationResult<bool>();
            result.Data = false;
            if (UpdataEntity(query) > 0)
            {
                result.Data = true;
            }
            return result;
        }
    }
}
